//
//  WithdrawWayViewController.m
//  YongChuanTradingArea
//
//  Created by Vivian on 2017/9/12.
//  Copyright © 2017年 李冰. All rights reserved.
//

#import "WithdrawWayViewController.h"
#import "WithdrawWayCell.h"
#import "WithdrawViewController.h"

static NSString * const WithdrawWayCellID = @"WithdrawWayCell";

@interface WithdrawWayViewController ()

@property (nonatomic, strong) NSArray *imgArray;

@property (nonatomic, strong) NSArray *titleArray;

@property (nonatomic, strong) NSArray *subtitleArray;

@property (nonatomic, strong) UIButton *nextBtn;

@property (nonatomic, assign) WithdrawType type;

@end

@implementation WithdrawWayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"提现方式";
    [self setupArray];
    [self createUI];
    // Do any additional setup after loading the view.
}

- (void)setupArray{
    self.imgArray = @[@"ic_unionpay", @"ic_wechat_pay", @"ic_alipay"];
    self.titleArray = @[@"银行卡", @"微信", @"支付宝"];
    self.subtitleArray = @[[LBUserManage defaultManager].userModel.BANKNUMBER?:@"", @"微信账号", @"支付宝账号"];
}

- (void)createUI{
    [self.view addSubview:self.tableView];
    self.tableView.frame = CGRectMake(0, 0, lbScreenWidth, 60);
    self.tableView.rowHeight = 60;
    [self.tableView registerNib:[UINib nibWithNibName:WithdrawWayCellID bundle:nil] forCellReuseIdentifier:WithdrawWayCellID];
    self.tableView.scrollEnabled = NO;
    self.tableView.separatorInset = UIEdgeInsetsMake(0, 12, 0, 0);
    self.tableView.separatorColor = [UIColor colorWithHexString:@"#dcdcdc"];
    self.nextBtn = [[UIButton alloc]initWithFrame:CGRectMake(20, 200, lbScreenWidth - 40, 44)];
    [self.nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
    [self.nextBtn setBackgroundImage:[UIImage imageNamed:@"btn_apply_3"] forState:UIControlStateNormal];
    [self.nextBtn addTarget:self action:@selector(nextBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.nextBtn];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WithdrawWayCell *cell = [tableView dequeueReusableCellWithIdentifier:WithdrawWayCellID forIndexPath:indexPath];
    cell.bindBtn.hidden = YES;
    cell.selectBtn.hidden = YES;
    if (indexPath.row == 0) {
        if (![LBUserManage defaultManager].userModel.BANKNUMBER) {
            cell.bindBtn.hidden = NO;
        }else{
            cell.selectBtn.hidden = NO;
        }
    }
    if (indexPath.row == 1) {
        cell.selectBtn.hidden = NO;
        self.type = WithdrawTypeWechat;
        [tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    }else{
        cell.hidden = YES;
    }
    if (indexPath.row == 2) {
        cell.selectBtn.hidden = NO;
    }
    cell.ImgView.image = [UIImage imageNamed:self.imgArray[indexPath.row]];
    cell.titleLabel.text = self.titleArray[indexPath.row];
    cell.subtitleLabel.text = self.subtitleArray[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 1) {
        return 60;
    }
    return CGFLOAT_MIN;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        self.type = WithdrawTypeBank;
    }
    if (indexPath.row == 1) {
        self.type = WithdrawTypeWechat;
    }
    if (indexPath.row == 2) {
        self.type = WithdrawTypeAliPay;
    }
}

#pragma mark - btn clicked
- (void)nextBtnAction{
    if (![LBUserManage defaultManager].userModel.BANKNUMBER && self.type == WithdrawTypeBank) {
        [MBProgressHUD showError:@"请选择提现方式！"];
        return;
    }
    if (self.type != WithdrawTypeWechat) {
        [MBProgressHUD showError:@"暂未开通"];
        return;
    }
    WithdrawViewController * vc = [[WithdrawViewController alloc]init];
    vc.amt = self.amt;
    vc.type = self.type;
    [self.navigationController pushViewController:vc animated:YES];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    
    return UIStatusBarStyleDefault;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

